package dao;

import com.mysql.jdbc.PreparedStatement;
import dto.Permissao;
import dto.Usuario;
import factory.daoUtil;
import generics.GenericoDao;
import java.sql.ResultSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Usuarios implements GenericoDao<Usuario> {

    public List<Usuario> select() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean insert(Usuario ob) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean edit(Usuario ob) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Usuario view(Usuario ob) {
        Usuario usuOb = new Usuario();

        String sql = "SELECT * FROM blogdb.usuario WHERE id = ?";

        Permissoes permDao = new Permissoes();

        try {
            try {

                PreparedStatement ps = (PreparedStatement) daoUtil.getInstance().getPrepareStatemen(sql);
                ps.setInt(1, ob.getId());

                ResultSet rs = ps.executeQuery();

                Permissao permOb = new Permissao();
                permOb.setId(rs.getInt("permissao_id"));
                permOb = permDao.view(permOb);

                while (rs.next()) {
                    usuOb.setId(rs.getInt("id"));
                    usuOb.setFlag(rs.getBoolean("flag"));
                    usuOb.setLogin(rs.getString("login"));
                    usuOb.setNome(rs.getString("nome"));
                    usuOb.setPermissao_id(permOb);
                    usuOb.setSenha(rs.getString("senha"));
                }

            } catch (Exception ex) {
                Logger.getLogger(Categorias.class.getName()).log(Level.SEVERE, null, ex);
            }
        } finally {
            daoUtil.getInstance().fecharTudo();
        }

        return usuOb;
    }

    public boolean delete(Usuario ob) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
